import { http } from '@/utils/request'
import type { AuthSuccessType, CaptchaType, LoginType } from '@/types/auth'

/**
 * 系统登录
 * @param data 请求参数
 */
export const loginAPI = (data: LoginType) => {
  return http.request<AuthSuccessType>('post', '/auth/login', { data }, true)
}

/**
 * 刷新token
 * @param refreshToken 刷新token
 */
export const refreshTokenAPI = (refreshToken: string | null) => {
  return http.request<AuthSuccessType>('post', '/auth/refresh', {
    data: { refreshToken, authType: 'password' }
  })
}

/**
 * 获取验证码
 */
export const getCaptchaAPI = () => {
  return http.request<CaptchaType>('post', '/auth/code')
}
